//
//  XTXXQViewController.m
//  xiaotianxin
//
//  Created by XYC on 2019/10/28.
//  Copyright © 2019 XYC. All rights reserved.
//

#import "XTXXQViewController.h"
#import "XTXXQTableViewController.h"
#import "XTXChatViewController.h"
#import "XTXChatModel.h"

@interface XTXXQViewController ()

@property (weak, nonatomic) IBOutlet UIButton *guanzhuBtn;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *layoutConst0;

@end

@implementation XTXXQViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.layoutConst0.constant = zhuangtaiGao+10;
    NSMutableDictionary *tempDict = [NSMutableDictionary dictionary];
    tempDict[@"f_user_id"] = self.userID;
    tempDict[@"user_id"] = XTXGongTool.share.useMode.id;
    [XTXNetworking networkingPushInfoClickdewangluoqingqiu:tempDict.copy completionHandler:^(NSDictionary * _Nonnull dict) {
        [self tryToParseData:dict];
    }];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:animated];
    [XTXGongTool huoquyonghuguanxiheguanzhuanniudeEventClick:self.userID withGzButton:self.guanzhuBtn];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:animated];
}

- (IBAction)dibutishikuanganniudedianjishijianClick:(UIButton *)sender {
    if (sender.tag == 0) {
        [XTXGongTool huoquyonghugetImV2dewangluoqingqiu:self.userID completionHandler:^(NSString * _Nonnull model) {
            if (model.integerValue == 1) {
                [XTXGongTool huoquyonghudegerenxinxiEventClick:self.userID completionHandler:^(XTXUserModel * _Nonnull model) {
                    dispatch_async(dispatch_get_main_queue(), ^{
                        XTXChatViewController *msgViewController = [[XTXChatViewController alloc] initWithNibName:NSStringFromClass(XTXChatViewController.class) bundle:nil];
                        XTXChatModel *msgmodel = [[XTXChatModel alloc] init];
                        msgmodel.user_id = XTXGongTool.share.useMode.id;
                        msgmodel.friend_user_id = self.userID;
                        msgmodel.message = @"";
                        msgmodel.headimage = model.headimage;
                        msgmodel.nickname = model.nickname;
                        msgmodel.sex = model.sex;
                        msgmodel.goddessflag = model.goddessflag;
                        msgViewController.mesageMod = msgmodel;
                        [self.navigationController pushViewController:msgViewController animated:YES];
                    });
                }];
            }
        }];
        
    }else if (sender.tag == 1) {
        // gz
        [XTXGongTool huoquyonghuguanzhuhequxiaoguanzhudeEventClcik:self.userID withGzButton:self.guanzhuBtn];
    }else if (sender.tag == 2) {
        [XTXGongTool huoquyonghudegerenxinxiEventClick:self.userID completionHandler:^(XTXUserModel * _Nonnull model) {
        }];
    }else if (sender.tag == 3) {
    }else if (sender.tag == 4) {
        [self.navigationController popViewControllerAnimated:YES];
    }else if (sender.tag == 5) {
        [XTXGongView.share zhanshijubaohelaheijiemianEventClick:self.userID withController:self];
    }
}

-(id)tryToParseData:(id)responseData {
    if ([responseData isKindOfClass:[NSData class]]) {
        // 尝试解析成JSON
        if (responseData == nil) {
            return responseData;
        } else {
            NSError *error = nil;
            NSDictionary *response = [NSJSONSerialization JSONObjectWithData:responseData
                                                                     options:NSJSONReadingMutableContainers
                                                                       error:&error];
            
            if (error != nil) {

                return responseData;
            } else {
                return response;
            }
        }
    } else {
        return responseData;
    }
}

#pragma mark - Navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    XTXXQTableViewController *infoTab = segue.destinationViewController;
    infoTab.userID = self.userID;
}

- (IBAction)callBtnClick:(id)sender {

}

@end
